<template>
	<view>
		<view class="m-list2">
			<view class="u-list2-itm" v-for="(item, index) in list" :key="index">
				<view v-if="item.state == 1" class="u-list2-itm-content">
					<view class="u-list2-l">
						<text class="global-fc">{{item.typeString}}</text>
						-{{item.address.address}}
						<text style="color: #ccc;">
							(审核中)
						</text>
					</view>
					<view class="u-list2-r">
						<image class="u-list2-r-img" src="../../static/icon/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view v-if="item.state == 2" class="u-list2-itm-content"
					@click="toPersonal(item.address.address, item.address.id, item.typeString, item.type, item.face_id, item.user_id)">
					<view class="u-list2-l">
						<text class="global-fc">{{item.typeString}}</text>
						<text>-{{item.address.address}}</text>
						<text v-if="item.state == 2" style="color: #2a9f93;">
							(已通过)
						</text>
					</view>
					<view class="u-list2-r">
						<image class="u-list2-r-img" src="../../static/icon/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view v-if="item.state == 3" class="u-list2-itm-content"
					@click="notPass(item.remark, item.state, item.id)">
					<view class="u-list2-l">
						<text class="global-fc">{{item.typeString}}</text>
						-{{item.address.address}}
						<text v-if="item.state == 3" style="color: red;">
							(未通过)
						</text>
					</view>
					<view class="u-list2-r">
						<image class="u-list2-r-img" src="../../static/icon/arrow-right.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>

		<view class="m-submit">
			<button class="u-btn" @click="toAddIdentity">添加身份</button>
		</view>
	</view>
</template>

<script>
	import USER from '@/api/user/index.js'
	let app = getApp();

	export default {
		data() {
			return {
				list: []
			}
		},
		mounted() {
			this.getIdentityList();
		},
		methods: {
			// 获取用户身份列表
			getIdentityList() {
				var self = this;
				uni.showLoading({
					title: '获取数据中',
					mask: true
				});
				USER.identityInfo(1, 10).then(res => {
					uni.hideLoading();
					if (res.data.data.length > 0) {
						self.list = res.data.data;
						self.list.forEach(item => {
							if (item.state == 3) {
								uni.showToast({
									title: '您有审核未通过的身份，请点击对应身份查看',
									icon: 'none',
									duration: 3000
								})
							}
						})
					} else {
						uni.showModal({
							title: '未添加身份提示',
							content: '您还未添加身份，无法使用部分功能，请先添加身份。如已添加身份，请等待户主(房东)审核通过',
							cancelText: '我已知晓',
							confirmText: '添加身份',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/my/info/index?nav_name=' + 'register'
									})
								} else if (res.cancel) {
									console.log('我已知晓');
								}
							}
						});
					}
				})
			},
			toPersonal(address, id, typeString, type, face_id, user_id) {
				app.globalData.intoRentAddressId = id; // 进入的出租屋地址id
				app.globalData.intoRentAddressName = address; // 进入的出租屋地址名称
				app.globalData.intoIdentity = typeString; // 进入的出租屋的身份
				app.globalData.intoIdentityType = type; // 进入的出租屋的身份id
				app.globalData.intoFaceId = face_id; // 进入的出租屋的人脸id
				app.globalData.intoUserId = user_id; // 进入的出租屋的人脸id

				uni.reLaunch({
					url: "/pages/my/personal",
					success() {
						console.log(434)
					},
					fail() {
						console.log(374)
					}
				})
			},
			// 查看未审核通过的原因
			notPass(remark, state, id) {
				uni.showModal({
					title: '未通过原因',
					content: remark ? remark : "未说明",
					cancelText: '我已知晓',
					confirmText: '前往修改',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/my/info/index?audit_state=' + state + '&identity_id=' + id
							})
						} else if (res.cancel) {
							console.log('我已知晓');
						}
					}
				});
			},
			// 前往添加身份
			toAddIdentity() {
				uni.navigateTo({
					url: '/pages/my/addIdentity/index'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	// .id-choose {

	// 	.choose-list-item {
	// 		display: flex;
	// 		justify-content: space-between;
	// 		align-items: center;
	// 		padding: 40rpx 20rpx;
	// 		border-bottom: 1rpx solid #ccc;
	// 		font-size: 36rpx;

	// 		.choose-list-item-text {
	// 			width: 600rpx;
	// 		}

	// 		.choose-list-item-image {
	// 			width: 40rpx;
	// 			height: 40rpx;
	// 		}
	// 	}

	// 	.global-fc {
	// 		color: $global-fc;
	// 	}
	// }
</style>
